using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace THANHTUNGO.Portal.Modules.DOWNLOAD.Components
{
    public partial class Item
    {
        public static int DownloadCount(int itemID)
        {
            string spName = "p_DOWNLOAD_Item_DownloadCount";
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand(spName);
            db.AddInParameter(dbCommand, "@ItemID", DbType.Int32, itemID);
            return db.ExecuteNonQuery(dbCommand);
        }

        public static DataSet SelectBy_ModuleID(int moduleID)
        {
            string spName = "p_DOWNLOAD_Item_SelectBy_ModuleID";
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand(spName);
            db.AddInParameter(dbCommand, "@ModuleID", DbType.Int32, moduleID);
            return db.ExecuteDataSet(dbCommand);
        }

        public static DataSet SelectBy_ModuleID_CategoryID(int moduleID, int categoryID)
        {
            if (categoryID == 0)
            {
                return SelectBy_ModuleID(moduleID);
            }
            string spName = "p_DOWNLOAD_Item_SelectBy_ModuleID_CategoryID";
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand(spName);
            db.AddInParameter(dbCommand, "@ModuleID", DbType.Int32, moduleID);
            db.AddInParameter(dbCommand, "@CategoryID", DbType.Int32, categoryID);

            return db.ExecuteDataSet(dbCommand);
        }
    }
}